<template>
  <div :class="['left-side-bar', siderBg]">
    <div class="bar-title">
      <svg-icon
        :icon-class="logoName"
        :size="26"
      />
      <div>{{ ENV_CONFIG.PRODUCTION_NAME }}</div>
    </div>
    <div class="all-version-title">
      所有版本
    </div>
    <div class="list-container">
      <div
        v-for="item in firstCatalogList"
        :key="item.id"
        :class="`list-item ${active===item.category_id?'active':''}`"
        @click="changeTab(item.category_id)"
      >
        <!-- <svg-icon
          :icon-class="active===item.id?item.hoverIcon:item.normalIcon"
          :size="20"
        /> -->
        <img
          :src="item.logo"
          class="item-img"
        >
        <div class="list-item-title">
          {{ item.title }}
        </div>
      </div>
    </div>
    <el-tooltip
      effect="light"
      :visible="downingShowTip"
    >
      <template
        #content
      >
        <div>点击<span style="color:#1E8CFF;">下载中心</span>即可查看下载</div>
        <div>进度，了解更多下载详情哦~</div>
      </template>
      <div
        class="download-center"
        @click="openDownloadManage"
      >
        <svg-icon
          icon-class="download"
          :size="20"
        />
        <span>下载中心</span>
        <span
          v-if="downingRedFlag"
          class="dot"
        />
      </div>
    </el-tooltip>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import {useDownloadManageWindow} from '@/stores/download-manage-window'
import { storeToRefs } from 'pinia';

import { useFirstCatalogData } from '@/stores/first-catalog-data'
import {useDownloadManage } from '@/stores/download-manage'
import { getSecondCatalog } from '@/api'
import {useEnvConfig} from '@/config'
const {ENV_CONFIG} = useEnvConfig()
const active = ref<number>(-1);

const downloadManageWindowStore = useDownloadManageWindow();
const { downloadManageWindowId,masterWindowId}=storeToRefs(downloadManageWindowStore)

const firstCatalogDataStore = useFirstCatalogData();
const { firstCatalogList, firstCatalogId } = storeToRefs(firstCatalogDataStore)

const downloadManageStore = useDownloadManage();
const { downingRedFlag,downingShowTip }=storeToRefs(downloadManageStore)

const getSecondCatalogData =async  () => {//获取第二层目录的数据
  const { code, data } = await getSecondCatalog({
    first_category_id:firstCatalogId.value,
    second_category_id:active.value
  })
  if (code === 200) {
    firstCatalogDataStore.setFirstCatalogTableValueList(data.item_data)
    firstCatalogDataStore.setUtilList(data.module?.module_items || [])
    firstCatalogDataStore.setUtilTitle(data.module?.title)
  }
}

const openDownloadManage = () => {//打开下载管理
  downloadManageStore.resetDowningRedFlag();
  downloadManageWindowStore.openDownloadManageWindow('1');
}

watch(firstCatalogList, (newList) => {//初始化第一个id处于选中状态
  if (newList.length&&active.value===-1) {
    active.value = newList[0].category_id
    getSecondCatalogData();
  }
})

const changeTab = (id: number) => {
  active.value = id;
  getSecondCatalogData();
}


const logoName=`logo-main-${ENV_CONFIG.type}`
const siderBg = `bg-${ENV_CONFIG.type}`
</script>

<style scoped lang="scss">
.left-side-bar {
  width: 154px;
  overflow: hidden;
  position: absolute;
  left: 8px;
  top: 10px;
  bottom: 10px;
  border-radius: 6px;
  background-repeat: no-repeat;
  background-size: cover;
  background: #192655;
  &.bg-cs{
    background-image: url(../assets/bg-cs.png);
  }
  &.bg-pvz {
    background-image: url(../assets/bg-pvz.png);
  }
  &.bg-redAlert {
    background-image: url(../assets/bg-redAlert.png);
  }
  &.bg-spiderPaper {
    background-image: url(../assets/bg-spiderPaper.png);
  }
  &.bg-warcraft {
    background-image: url(../assets/bg-warcraft.png);
  }
  .bar-title{
    display: flex;
    gap:5px;
    align-items: center;
    justify-content: flex-start;
    margin:15px 0 40px 15px;
    
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: 14px;
    color: #FFFFFF;
    line-height: 16px;
  }
  .all-version-title{
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: 12px;
    color: rgba(255,255,255,0.7);
    line-height: 14px;
    margin:0 0 10px 10px;
  }
  .list-container{
    display: flex;
    flex-direction: column;
    gap:10px;
    .item-img{
      width:20px;
      height:20px;
      
    }
    .list-item{
      height:44px;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap:5px;
      padding-left: 20px;

      font-family: Microsoft YaHei, Microsoft YaHei;
      font-weight: 400;
      font-size: 12px;
      color: #FFFFFF;
      cursor: pointer;
      line-height: 14px;
      .list-item-title{
        position: relative;
        z-index: 2;
        text-overflow: ellipsis;
        overflow:hidden;
        white-space: nowrap;
      }
      &:hover{
        background:rgba(255,255,255,0.3);
      }
      &.active{
        background:#fff;
        color:rgba(51, 51, 51, 1);
        font-weight: bold;
        position:relative;
        &::before{
          content:'';
          position: absolute;
          z-index: 1;
          width:76px;
          height:76px;
          right:-12px;
          top:50%;
          transform: translate(50%,-50%);
          background: url('@/assets/svg/first-catalog-mask-bg.svg') no-repeat center/cover;
        }
      }
    }
  }
  .download-center{
    position: absolute;
    bottom:20px;
    left:0;
    right:0;
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    cursor: pointer;
    &:hover{
      color: rgba($color: #fff, $alpha: 0.8);
    }
    .dot{
      width:8px;
      height: 8px;
      border-radius: 50%;
      background:#E00000;
      position: absolute;
      right: calc(50% - 4em);
      top: 0;
    }
  }
}
</style>